package com.fa4j.product.item.model;

import com.fa4j.common.base.model.AbstractCmd;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
@Schema(description = "商品信息创建参数")
public class ItemCreateCmd extends AbstractCmd {

    @NotBlank
    @Size(max = 32)
    @Schema(description = "商品标题")
    private String title;

    @NotBlank
    @Size(max = 64)
    @Schema(description = "商品描述")
    private String description;

    @NotNull
    @Schema(description = "商品分类")
    private Integer categoryId;

    @NotNull
    @Schema(description = "商品类型")
    private ItemType type;

    @NotNull
    @Schema(description = "商品图片视频列表")
    private List<Long> mediaIds;

    @Schema(description = "商品详情图片列表")
    private List<Long> detailImgIds;

    @Size(max = 16)
    @Schema(description = "商品单位")
    private String unit;

    @NotEmpty
    @Schema(description = "商品规格列表")
    private List<@Valid Spec> specList;

    @Schema(description = "商品属性列表")
    private List<@Valid Attr> attrList;

    @Schema(description = "商品规格参数")
    public record Spec(
            @Schema(description = "商品规格图片")
            Long imageId,
            @NotNull
            @PositiveOrZero
            @Schema(description = "商品规格价格")
            BigDecimal price,
            @PositiveOrZero
            @Schema(description = "商品规格重量")
            BigDecimal weight,
            @Schema(description = "商品规格条码")
            String barcode,
            @Schema(description = "商品规格属性列表")
            List<@Valid Attr> attrList,

            @Schema(description = "库存数量")
            BigDecimal stockQuantity
    ) {
    }

    @Schema(description = "商品属性参数")
    public record Attr(
            @NotEmpty
            @Size(max = 32)
            @Schema(description = "商品属性名称")
            String attrName,
            @NotEmpty
            @Size(max = 32)
            @Schema(description = "商品属性值")
            String attrValue
    ) {
    }

}
